<template>
  <div class="p-2">
    <el-row :gutter="20">
      <el-col :lg="24" :xs="24">
        <div v-show="showSearch" class="mb-[10px]">
          <el-card shadow="hover">
            <el-form ref="queryFormRef" :model="queryParams" :inline="true">
              <el-form-item label="试剂名称" prop="userName">
                <el-input v-model="queryParams.userName" placeholder="请输入试剂名称" clearable @keyup.enter="handleQuery" />
              </el-form-item>
              <el-form-item>
                <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
                <el-button icon="Refresh" @click="resetQuery">重置</el-button>
              </el-form-item>
            </el-form>
          </el-card>
        </div>

        <el-card shadow="hover">
          <template #header>
            <el-row :gutter="10">
              <el-col :span="1.5">
                <el-button type="primary" plain icon="Plus" @click="handleAdd()">新增</el-button>
              </el-col>
              <right-toolbar v-model:show-search="showSearch" :columns="columns" :search="true" @query-table="getList"></right-toolbar>
            </el-row>
          </template>

          <el-table v-loading="loading" border :data="listData" @selection-change="handleSelectionChange">
            <el-table-column type="selection" width="50" align="center" />
            <template v-for="(item, index) in columns">
              <el-table-column v-if="item.visible"
                               :key="item.key"
                               :label="item.label"
                               align="center"
                               :width="item.width"
                               :prop="item.key" >

              </el-table-column>
            </template>

            <el-table-column label="操作" fixed="right" width="180" class-name="small-padding fixed-width">
              <template #default="scope">
                <el-button link type="primary" @click="handleEdit(scope.row)" icon="Edit">修改</el-button>
              </template>
            </el-table-column>
          </el-table>

          <pagination
            v-show="total > 0"
            v-model:page="queryParams.pageNum"
            v-model:limit="queryParams.pageSize"
            :total="total"
            @pagination="getList"
          />
        </el-card>
      </el-col>
    </el-row>

    <formVue ref="formRef"></formVue>

  </div>
</template>

<script setup>
// 方法
import { ref } from 'vue'
// 组件
import formVue from '@/views/property/reagent/form.vue'
const formRef = ref(null)
// 列显隐信息
const columns = ref([
  { "key": "试剂名称", "label": "试剂名称", "visible": true, "width": 120, "children": [] },
  { "key": "单位", "label": "单位", "visible": true, "width": 120, "children": [] },
  { "key": "库存数量", "label": "库存数量", "visible": true, "width": 120, "children": [] },
  { "key": "价格", "label": "价格", "visible": true, "width": 120, "children": [] },
  { "key": "批次号", "label": "批次号", "visible": true, "width": 120, "children": [] },
  { "key": "生产日期", "label": "生产日期", "visible": true, "width": 120, "children": [] },
  { "key": "规格", "label": "规格", "visible": true, "width": 120, "children": [] },
  { "key": "试剂编号", "label": "试剂编号", "visible": true, "width": 120, "children": [] },
  { "key": "安全等级", "label": "安全等级", "visible": true, "width": 120, "children": [] },
  { "key": "纯度", "label": "纯度", "visible": true, "width": 120, "children": [] },
  { "key": "供应商", "label": "供应商", "visible": true, "width": 150, "children": [] },
  { "key": "有效期", "label": "有效期", "visible": true, "width": 120, "children": [] },
  { "key": "储存条件", "label": "储存条件", "visible": true, "width": 120, "children": [] },
  { "key": "使用频率", "label": "使用频率", "visible": true, "width": 120, "children": [] },
  { "key": "备注", "label": "备注", "visible": true, "width": 200, "children": [] }
]);

const queryParams = ref({
  pageNum: 1,
  pageSize: 10,
})
const total = ref(0)
const showSearch = ref(true);
const loading = ref(true);
const listData = ref([
  {
    "单位": "瓶",
    "库存数量": 125,
    "价格": 85.00,
    "批次号": "20250615A",
    "生产日期": "2025-06-15",
    "试剂名称": "无水乙醇",
    "规格": "500mL/瓶",
    "试剂编号": "R-202506001",
    "安全等级": "B级",
    "纯度": "分析纯（AR）",
    "供应商": "国药集团化学试剂有限公司",
    "有效期": "2027-06-14",
    "储存条件": "阴凉干燥处，远离火源",
    "使用频率": "高",
    "备注": "用于常规化学分析，需注意防火"
  },
  {
    "单位": "盒",
    "库存数量": 36,
    "价格": 245.00,
    "批次号": "20250520B",
    "生产日期": "2025-05-20",
    "试剂名称": "氢氧化钠标准溶液",
    "规格": "0.1mol/L，500mL/瓶",
    "试剂编号": "R-202505002",
    "安全等级": "C级",
    "纯度": "滴定分析用标准溶液",
    "供应商": "上海泰坦科技股份有限公司",
    "有效期": "2026-05-19",
    "储存条件": "密封保存，防止吸收CO₂",
    "使用频率": "中",
    "备注": "需定期标定浓度，瓶身有标定记录贴纸"
  },
  {
    "单位": "支",
    "库存数量": 15,
    "价格": 1200.00,
    "批次号": "20250310C",
    "生产日期": "2025-03-10",
    "试剂名称": "硝酸银",
    "规格": "5g/支",
    "试剂编号": "R-202503005",
    "安全等级": "A级",
    "纯度": "优级纯（GR）",
    "供应商": "阿拉丁试剂（上海）有限公司",
    "有效期": "2028-03-09",
    "储存条件": "避光、低温、干燥保存",
    "使用频率": "低",
    "备注": "见光易分解，使用时需佩戴防护手套"
  },
  {
    "单位": "箱",
    "库存数量": 8,
    "价格": 1800.00,
    "批次号": "20250405D",
    "生产日期": "2025-04-05",
    "试剂名称": "盐酸（37%）",
    "规格": "2.5L/瓶，4瓶/箱",
    "试剂编号": "R-202504003",
    "安全等级": "A级",
    "纯度": "分析纯（AR）",
    "供应商": "西陇科学股份有限公司",
    "有效期": "2027-04-04",
    "储存条件": "阴凉通风处，与碱类、金属粉末分开存放",
    "使用频率": "高",
    "备注": "强腐蚀性，使用时需在通风橱操作"
  },
  {
    "单位": "袋",
    "库存数量": 42,
    "价格": 35.00,
    "批次号": "20250701E",
    "生产日期": "2025-07-01",
    "试剂名称": "氯化钠",
    "规格": "500g/袋",
    "试剂编号": "R-202507001",
    "安全等级": "D级",
    "纯度": "基准试剂",
    "供应商": "麦克林生化科技有限公司",
    "有效期": "2030-06-30",
    "储存条件": "密封保存，防止潮解",
    "使用频率": "中",
    "备注": "用于配制标准溶液，开封后需防潮"
  }
]);


// 获取数据
const getList = () => {
  loading.value = false
}

// 搜索
const handleQuery = () => {
}

// 重置
const resetQuery = () => {
  for (let i in queryParams.value) {
    if (i !== 'pageNum' && i !== 'pageSize') {
      queryParams.value[i] = undefined
    }
  }
  handleQuery()
}

// 多选
const handleSelectionChange = () => {
}

// 新增
const handleAdd = () => {
  formRef.value.open()
}
// 编辑
const handleEdit = (item) => {
  formRef.value.edit(item)
}


getList()
</script>
